Apparatus, system, and method for clipping graphics primitives with accelerated context switching

ABSTRACT

An apparatus, system, and method for clipping graphics primitives are described. In one embodiment, a graphics processing apparatus includes a clipping unit that is configured to issue an initial set of outputs based on execution of a set of clipping operations. The graphics processing apparatus also includes a control unit that is connected to the clipping unit. The control unit is configured to preserve an initial execution state of the clipping unit in response to an initial command for context switching, and the initial execution state is preserved based on a number of the initial set of outputs.

BRIEF DESCRIPTION OF THE INVENTION

The invention relates generally to graphics processing. More particularly, the invention relates to an apparatus, system, and method for clipping graphics primitives with accelerated context switching.

BACKGROUND OF THE INVENTION

Advanced Graphics Processing Units (“GPUs”) sometimes implement techniques for context switching. In general, context switching refers to switching execution among multiple contexts such that those contexts can share a common processing resource. Multiple contexts can be related to distinct operation modes of the same application program or multiple application programs.

In order to accelerate graphics processing, it is desirable to reduce a response time for context switching. As can be appreciated, this response time represents a performance penalty for context switching and is typically dependent upon a pair of factors, namely an amount of time to complete any pending work and an amount of execution state information to be stored and restored. Typically, a larger amount of time to complete any pending work translates into a longer response time, thus resulting in a larger performance penalty. Similarly, a larger amount of execution state information to be stored and restored typically translates into a longer response time and a larger performance penalty. Unfortunately, current techniques for context switching can be deficient from the standpoint of one or both of these factors, particularly with respect to clipping graphics primitives.

One current technique for context switching is a “wait for idle” technique. In accordance with this technique, context switching is typically placed on hold so as to complete any pending work in connection with clipping a graphics primitive. While an amount of execution state information to be stored and restored is thus reduced, completing the pending work often takes an undesirable amount of time. Indeed, in some instances, completing the pending work can take hundreds of clock cycles, particularly when clipping the graphics primitive with respect to multiple clipping planes. Another current technique for context switching is a “halt style” technique. In accordance with this technique, any pending work in connection with clipping a graphics primitive is halted prior to its completion to allow context switching. While an amount of time to complete the pending work is thus reduced, an amount of execution state information to be stored and restored is often undesirably large, particularly given the extensive amount of information that is typically maintained in hardware while clipping the graphics primitive. Indeed, in some instances, storing and restoring the execution state information can take numerous clock cycles.

It is against this background that a need arose to develop the apparatus, system, and method described herein.

SUMMARY OF THE INVENTION

In one aspect, the invention relates to a graphics processing apparatus. In one embodiment, the graphics processing apparatus includes a clipping unit that is configured to issue an initial set of outputs based on execution of a set of clipping operations. The graphics processing apparatus also includes a control unit that is connected to the clipping unit. The control unit is configured to preserve an initial execution state of the clipping unit in response to an initial command for context switching, and the initial execution state is preserved based on a number of the initial set of outputs.

In another aspect, the invention relates to a clipping unit. In one embodiment, the clipping unit includes a clipping engine that is configured to produce outputs for a current context. The clipping unit also includes an output unit that is connected to the clipping engine. The output unit is configured to selectively issue a subset of the outputs based on whether the subset of the outputs is yet to be issued for the current context.

In a further aspect, the invention relates to a graphics processing method. In one embodiment, the graphics processing method includes issuing an initial set of outputs based on clipping of a graphics primitive. The graphics processing method also includes, in response to an initial command for context switching: (i) suspending the clipping of the graphics primitive; and (ii) preserving an initial execution state based on an indication that the initial set of outputs has already been issued.

Other aspects and embodiments of the invention are also contemplated. The foregoing summary and the following detailed description are not meant to restrict the invention to any particular embodiment but are merely meant to describe some embodiments of the invention.

BRIEF DESCRIPTION OF THE DRAWINGS

For a better understanding of the nature and objects of some embodiments of the invention, reference should be made to the following detailed description taken in conjunction with the accompanying drawings, in which:

FIG. 1 illustrates a computer system that is implemented in accordance with an embodiment of the invention;

FIG. 2 illustrates a clipping module that is implemented in accordance with an embodiment of the invention;

FIG. 3 illustrates an example of operation of the clipping module of FIG. 2; and

FIG. 4 illustrates another example of operation of the clipping module of FIG. 2.

Like reference numerals are used to refer to corresponding components of the drawings.

DETAILED DESCRIPTION

FIG. 1 illustrates a computer system 100 that is implemented in accordance with an embodiment of the invention. The computer system 100 includes a computer 102, which can be, for example, a desktop computer, a server computer, a laptop computer, a palm-sized computer, a tablet computer, a game console, a portable wireless terminal such as a personal digital assistant or a cellular telephone, a computer-based simulator, or any other device with data processing capability. As illustrated in FIG. 1, the computer 102 is connected to a set of input devices 104, which can include, for example, a keyboard and a mouse. The computer 102 is also connected to a display device 106, which can be, for example, a television set, a Cathode Ray Tube (“CRT”) monitor, or a Liquid Crystal Display (“LCD”) monitor.

The computer 102 includes a Central Processing Unit (“CPU”) 108, which is connected to a memory 110 over a bus 122. Referring to FIG. 1, the memory 110 stores a set of application programs 124, which can include, for example, a set of graphics programs. The memory 110 can include, for example, a Random Access Memory (“RAM”) and a Read Only Memory (“ROM”). As illustrated in FIG. 1, the computer 102 also includes a graphics processing apparatus 112 that is connected to the CPU 108 and the memory 110 over the bus 122. The graphics processing apparatus 112 can be, for example, a GPU.

In the illustrated embodiment, the graphics processing apparatus 112 performs a number of operations when servicing a particular context related to the application programs 124. This context can be related to a particular operational mode of the application programs 124, such as a three-dimensional (“3-D”) graphics mode, a two-dimensional (“2-D”) graphics mode, or a video mode. Referring to FIG. 1, the graphics processing apparatus 112 includes a graphics pipeline 114, which includes a number of modules that are connected to one another and that form different stages of the graphics pipeline 114. In particular, the graphics pipeline 114 includes a transformation module 116, a clipping module 118, and a rasterization module 120. While three modules are illustrated in FIG. 1, it is contemplated that the graphics pipeline 114 can include more or less modules depending on the particular implementation. It is also contemplated that these modules can be combined, sub-divided, or re-ordered for another implementation. Referring to FIG. 1, the graphics processing apparatus 112 also includes a local memory 126 that is connected to the graphics pipeline 114. As further described below, the local memory 126 stores execution state information in connection with context switching. However, it is also contemplated that the memory 110 can be used to store the execution state information, such that the local memory 126 can be omitted for certain implementations. The local memory 126 can include, for example, a RAM.

During execution of a particular context, the transformation module 116 initially receives a graphics primitive that represent an object to be displayed. Examples of graphics primitives include one-dimensional graphics primitives, such as lines, and two-dimensional graphics primitives, such as polygons. Referring to FIG. 1, the transformation module 116 performs a number of transformation operations on the graphics primitive. For example, coordinate data of vertices defining the graphics primitive can be rotated, scaled, translated, or converted from one coordinate space into another coordinate space. It is also contemplated that color data, specularity data, or texture data of the vertices can be modified, such as in connection with lighting operations. The transformation module 116 then delivers the graphics primitive that has been transformed in such manner to the clipping module 118.

Referring to FIG. 1, the clipping module 118 next clips the graphics primitive with respect to a set of clipping planes to produce a clipped graphics primitive. The clipping module 118 then delivers the clipped graphics primitive to the rasterization module 120. It is also contemplated that multiple clipped graphics primitives can be produced as a result of clipping the graphics primitive. In the illustrated embodiment, the clipping planes define a viewing region, which can be a two-dimensional viewing area or a three-dimensional viewing volume. It is also contemplated that the clipping planes can alternatively, or in conjunction, include a set of model clipping planes, which can be specified by a user to further restrict the viewing region or to remove certain portions of the object from view. It is further contemplated that the clipping planes can alternatively, or in conjunction, include a w=0 plane in homogeneous space. As can be appreciated, the w=0 plane can be positioned at a viewpoint of the viewing region, such that portions of the object that lie on a w<0 side of that plane are behind the viewpoint and are, thus, not visible. The clipping module 118 serves to increase efficiency of the graphics pipeline 114, as further processing on portions of the object that lie outside the viewing region need not be performed. Also, by using the set of model clipping planes, the clipping module 118 allows portions of the object that were previously hidden from view to be visualized. Furthermore, by using the w=0 plane, the clipping module 118 serves to avoid further processing on portions of the object that are behind the viewpoint.

Referring to FIG. 1, the rasterization module 120 next performs a number of interpolation operations on the clipped graphics primitive to produce a set of pixels that represent the object to be displayed. For example, coordinate data of vertices defining the clipped graphics primitive can be interpolated to assign the pixels to represent the object. It is also contemplated that color data, specularity data, or texture data of the vertices can be interpolated in connection with pixel assignment. The rasterization module 120 then delivers the pixels for display using the display device 106.

The foregoing describes operation of the graphics processing apparatus 112 in the absence of context switching. Advantageously, the graphics processing apparatus 112 also operates in accordance with an improved technique for context switching. This improved technique provides the graphics processing apparatus 112 with multi-tasking capabilities by allowing the graphics processing apparatus 112 to efficiently service multiple contexts related to the application programs 124. In particular, when execution switches from a first context to a second context, the graphics processing apparatus 112 preserves an execution state of the first context prior to servicing the second context. The execution state of the first context represents a degree of progress of execution of the first context. Subsequent to servicing the second context, the graphics processing apparatus 112 restores the execution state of the first context so that the execution of the first context can proceed. In connection with context switching, execution state information of the first context is collected from the transformation module 116, the clipping module 118, and the rasterization module 120, and this execution state information is then delivered to the local memory 126 for storage. Subsequent to servicing the second context, this execution state information is retrieved from the local memory 126 and then restored to the transformation module 116, the clipping module 118, and the rasterization module 120. In the illustrated embodiment, context switching is typically initiated by the CPU 108, which issues a context switching command that is delivered to the graphics processing apparatus 112 over the bus 122. However, it is also contemplated that context switching can be initiated by the graphics processing apparatus 112.

With respect to the clipping module 118, context switching is implemented so as to reduce both an amount of time to complete any pending work and an amount of execution state information to be stored and restored. In particular, in response to receiving a context switch command, the clipping module 118 suspends clipping a graphics primitive in accordance with the first context. Advantageously, clipping the graphics primitive is suspended prior to its completion and with little or no delay upon receiving the context switching command. The clipping module 118 then collects execution state information of the first context and delivers this execution state information to the local memory 126 for storage. Advantageously, this execution state information represents a reduced and optimized set of information to preserve an execution state of clipping the graphics primitive and need not include a variety of other information that is maintained in the clipping module 118. In particular, as further described below, this execution state is readily preserved based on how many outputs have already been issued by the clipping module 118 in connection with clipping the graphics primitive. Subsequent to servicing the second context, this execution state is restored to the clipping module 118, which resumes issuing outputs that have not yet been issued in connection with clipping the graphics primitive. By operating in such manner, the clipping module 118 allows context switching to be performed in an accelerated manner so as to reduce a performance penalty for context switching. In addition, such accelerated context switching is achieved with little or no additional cost or complexity as compared with a conventional implementation.

Attention next turns to FIG. 2, which illustrates the clipping module 118 that is implemented in accordance with an embodiment of the invention. The clipping module 118 includes a vertex memory 202, which receives and stores a set of inputs defining a graphics primitive to be clipped in accordance with a first context. The inputs can include, for example, coordinate data, color data, specularity data, and texture data of vertices defining the graphics primitive. The vertex memory 202 can be implemented as, for example, a RAM that stores the inputs in accordance with an order in which the inputs are received.

As illustrated in FIG. 2, the clipping module 118 also includes a clipping unit 204, which clips the graphics primitive with respect to a set of clipping planes to produce a clipped graphics primitive. Referring to FIG. 2, the clipping unit 204 includes a clipping engine 206, which is connected to the vertex memory 202. The clipping engine 206 accesses the inputs that are stored in the vertex memory 202 and executes a set of clipping operations to produce a set of outputs defining the clipped graphics primitive. The outputs can include, for example, coordinate data, color data, specularity data, and texture data of vertices defining the clipped graphics primitive. In the absence of context switching, the clipping engine 206 typically completes execution of the clipping operations without interruption. On the other hand, in the event of context switching, the clipping engine 206 suspends the execution of the clipping operations prior to completion. Upon resuming the first context, the clipping engine 206 restarts the execution of the clipping operations from the beginning. In the illustrated embodiment, the clipping engine 206 executes the clipping operations in accordance with any suitable clipping technique, such as the Cohen-Sutherland technique, the Liang-Barsky technique, the Sutherland-Hodgeman technique, or the Weiler technique. The clipping engine 206 can be implemented as, for example, a micro-coded engine including a ROM that stores a clipping program for executing the clipping operations.

Referring to FIG. 2, the clipping unit 204 also includes an output unit 208, which is connected to the clipping engine 206. The output unit 208 issues one or more of the outputs that are produced by the clipping engine 206 for the first context. In the absence of context switching, the output unit 208 typically issues all of the outputs that are produced by the clipping engine 206. On the other hand, in the event of context switching, the output unit 208 selectively issues particular ones of the outputs based on whether those outputs have yet to issued for the first context. In such manner, the output unit 208 avoids reissuing remaining ones of the outputs that have already been issued prior to resuming the first context. As illustrated in FIG. 2, the output unit 208 references contents of a pair of counters 210 and 212 to determine which ones of the outputs should be issued for the first context. While the counters 210 and 212 are illustrated as being included in the output unit 208, it is also contemplated that the counters 210 and 212 can be implemented elsewhere.

As illustrated in FIG. 2, the clipping module 118 further includes a control unit 214, which is connected to and coordinates operations that are performed by the vertex memory 202 and the clipping unit 204. In the event of context switching, the control unit 214 preserves an execution state of clipping the graphics primitive in accordance with the first context. In particular, the execution state is preserved simply based on contents of the vertex memory 202 and the counter 212. Upon resuming the first context, the control unit 214 restores the contents of the vertex memory 202 and the counter 212 so that clipping the graphics primitive can proceed. In the illustrated embodiment, the control unit 214 receives context switching commands from the CPU 108 (not illustrated in FIG. 2) and routes execution state information to and from the local memory 126 (not illustrated in FIG. 2). Referring to FIG. 2, the control unit 214 issues a stall signal so as to hold the inputs of the vertex memory 202 prior to completion of clipping the graphics primitive. In such manner, the inputs are not overwritten in the vertex memory 202 by a subsequent set of inputs and remain accessible in the event that clipping the graphics primitive is restarted. The control unit 214 can be implemented in any suitable manner, such as using computer code, hardwired circuitry, or a combination of computer code and hardwired circuitry.

Advantages and features of the clipping module 118 can be further understood in conjunction with FIG. 3 and FIG. 4, which illustrate examples of the operation of the clipping module 118.

FIG. 3 illustrates an example of the operation of the clipping module 118 in the absence of context switching. In particular, at T_(start), the vertex memory 202 receives and stores a sequence of inputs defining a graphics primitive to be clipped in accordance with a first context. The clipping engine 206 next begins clipping the graphics primitive by accessing the inputs that are stored in the vertex memory 202. In the absence of context switching, the clipping engine 206 completes clipping the graphics primitive without interruption to produce a sequence of outputs O₁ through O_(n). In conjunction, the output unit 208 issues each of the outputs O₁ through O_(n) that are produced by the clipping engine 206. In the illustrated example, the counter 210 tracks a number of outputs that are produced as a result of clipping the graphics primitive, while the counter 212 tracks a number of outputs that are issued as a result of clipping the graphics primitive. In the absence of context switching, the counters 210 and 212 are incremented substantially in unison. To facilitate context switching as further described below, the counter 210 is cleared upon start of clipping the graphics primitive, namely at or around T_(start), while the counter 212 is not cleared until completion of clipping the graphics primitive, namely at or around T_(end).

FIG. 4 illustrates an example of the operation of the clipping module 118 in the event of context switching. In particular, at T_(start), the vertex memory 202 receives and stores a sequence of inputs defining a graphics primitive to be clipped in accordance with a first context. The clipping engine 206 next begins clipping the graphics primitive by accessing the inputs that are stored in the vertex memory 202. Prior to context switching, the clipping engine 206 partially completes clipping the graphics primitive to produce an initial sequence of outputs O₁ through O₃. In conjunction, the output unit 208 issues each of the outputs O₁ through O₃ that are produced by the clipping engine 206. As in the previous example, the counter 210 tracks a number of outputs that are produced as a result of clipping the graphics primitive, while the counter 212 tracks a number of outputs that are issued as a result of clipping the graphics primitive. Prior to context switching, the counters 210 and 212 are incremented substantially in unison.

Next, at T_(switch1), the control unit 214 receives an initial context switching command and directs the clipping unit 204 to switch to a second context. In response, the clipping engine 206 suspends clipping the graphics primitive in accordance with the first context. In conjunction, the control unit 214 collects contents of the vertex memory 202 and the counter 212 so as to preserve an execution state of clipping the graphics primitive. In particular, the control unit 214 retrieves a content of the counter 212 so as to preserve an indication that three outputs have already been issued as a result of clipping the graphics primitive. Upon switching to the second context, the clipping unit 204 can either service the second context or remain idle.

Referring to FIG. 4, at T_(switch2), the control unit 214 receives a subsequent context switching command and directs the clipping unit 204 to switch back to the first context. The control unit 214 also restores the contents of the vertex memory 202 and the counter 212 so as to restore the execution state of clipping the graphics primitive. In response, the clipping engine 206 restarts clipping the graphics primitive from the beginning so as to again produce the initial sequence of outputs O₁ through O₃. Restarting clipping the graphics primitive typically incurs little or no performance penalty, since an amount of time to produce the outputs O₁ through O₃ is typically less than or comparable to an amount of time to restore other components of the graphics pipeline 114. Thus, restarting clipping the graphics primitive can overlap the amount of time to restore other components of the graphics pipeline 114. In the absence of further context switching, the clipping engine 206 completes clipping the graphics primitive without further interruption to produce a remaining sequence of outputs O₄ through O_(n).

In conjunction, the output unit 208 selectively issues the outputs O₄ through O_(n) without reissuing the outputs O₁ through O₃. The output unit 208 can either discard the outputs O₁ through O₃ or designate these outputs as being invalid. In the illustrated example, the output unit 208 references contents of the counters 210 and 212 to determine which outputs should be issued. In particular, the counter 210 is cleared upon restart of clipping the graphics primitive, namely at or around T_(switch2), and again tracks a number of outputs that are produced as a result of clipping the graphics primitive. However, the counter 212 is not initially incremented so as to preserve the indication that three outputs have already been issued prior to resuming the first context. Thus, by comparing the contents of the counters 210 and 212, the output unit 208 will not issue any output until the output O₄ is produced, upon which the counters 210 and 212 are again incremented substantially in unison. In the absence of further context switching, the counter 212 is then cleared upon completion of clipping the graphics primitive, namely at or around T_(end). Alternatively, the clipping module 118 can operate in a similar manner as described above in the event of further context switching.

As can be appreciated at this point, embodiments of the invention allow context switching to be performed in an accelerated manner and with little or no additional cost or complexity as compared with a conventional implementation. In particular, context switching is accelerated by reducing both an amount of time to complete any pending work and an amount of execution state information to be stored and restored. For example, prior to context switching, a clipping program can be executed in accordance with an initial context to produce an initial sequence of outputs. In the event of context switching, execution of the clipping program can be suspended prior to its completion and with little or no delay. A reduced and optimized set of information can be collected so as to preserve an initial execution state of the clipping program. In particular, the initial execution state can be preserved simply based on contents of a vertex memory and a counter, without requiring other contents of an internal datapath pipeline or scratch registers to be stored and restored. Upon resuming the initial context, the initial execution state can be restored, and the clipping program can be restarted from the beginning. By referencing the initial execution state, a remaining sequence of outputs can be issued without reissuing the initial sequence of outputs.

It should be appreciated that the specific embodiments of the invention described above are provided by way of example, and various other embodiments are encompassed by the invention. For example, while some embodiments have been described with reference to clipping graphics primitives, it is contemplated that the improved technique for context switching can be similarly implemented for various applications, such as those in which a relatively large number of outputs are produced or those in which completing any pending work can take a relatively long time.

Some embodiments of the invention relate to a computer storage product with a computer-readable medium having computer code thereon for performing various computer-implemented operations. The media and computer code may be those specially designed and constructed for the purposes of the invention, or they may be of the kind well known and available to those having skill in the computer software arts. Examples of computer-readable media include, but are not limited to: magnetic storage media such as hard disks, floppy disks, and magnetic tape; optical storage media such as Compact Disc/Digital Video Discs (“CD/DVDs”), Compact Disc-Read Only Memories (“CD-ROMs”), and holographic devices; magneto-optical storage media such as floptical disks; carrier wave signals; and hardware devices that are specially configured to store and execute program code, such as Application-Specific Integrated Circuits (“ASICs”), Programmable Logic Devices (“PLDs”), and ROM and RAM devices. Examples of computer code include, but are not limited to, machine code, such as produced by a compiler, and files containing higher-level code that are executed by a computer using an interpreter. For example, an embodiment of the invention may be implemented using Java, C++, or other object-oriented programming language and development tools. Additional examples of computer code include, but are not limited to, encrypted code and compressed code.

Some embodiments of the invention can be implemented using computer code in place of, or in combination with, hardwired circuitry. For example, with reference to FIG. 2, various components of the clipping module 118 can be implemented using computer code, hardwired circuitry, or a combination thereof.

While the invention has been described with reference to the specific embodiments thereof, it should be understood by those skilled in the art that various changes may be made and equivalents may be substituted without departing from the true spirit and scope of the invention as defined by the appended claims. In addition, many modifications may be made to adapt a particular situation, material, composition of matter, method, process operation or operations, to the objective, spirit and scope of the invention. All such modifications are intended to be within the scope of the claims appended hereto. In particular, while the methods disclosed herein have been described with reference to particular operations performed in a particular order, it will be understood that these operations may be combined, sub-divided, or re-ordered to form an equivalent method without departing from the teachings of the invention. Accordingly, unless specifically indicated herein, the order and grouping of the operations is not a limitation of the invention. 

1. A clipping unit, comprising: a clipping engine configured to produce outputs for a current context, wherein the clipping engine is configured to produce the outputs based on execution of a set of clipping operations with respect to the current context, and the clipping engine is configured to restart the execution of the set of clipping operations in response to a command to switch from a previous context to the current context; and an output unit connected to the clipping engine, the output unit configured to selectively issue a subset of the outputs based on whether the subset of the outputs is yet to be issued for the current context, wherein the output unit is configured to selectively issue the subset of the outputs without reissuing a remaining subset of the outputs that has already been issued prior to restarting the execution of the set of clipping operations, and the output unit is configured to designate the remaining subset of the outputs as invalid.
 2. The clipping unit of claim 1, wherein the execution of the set of clipping operations is restarted from the beginning.
 3. The clipping unit of claim 1, wherein the output unit is configured to selectively issue the subset of the outputs based on how many of the outputs have already been issued prior to restarting the execution of the set of clipping operations.
 4. The clipping unit of claim 1, wherein the output unit is configured to track how many of the outputs have already been issued for the current context. 